-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchronize what gets compiled into libc_nonshared.a
with glibc
#16970
Conversation
This is great work! Thanks for doing this. I'm sorry that I did not look at this pull request until now. Are you willing to do the work of rebasing it? If so, let me know. Otherwise, I'll get to it over the next week or so. |
Oh, it took me a few days to notice this reply as well, don't mind :-) I'll try to rebase the PR this weekend. If I were not able to do that, you may ignore me and pick this up. |
2ce2233
to
3855b71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me. Nice cleanup in glibc.zig.
The scope of libc_nonshared.a was greatly changed in glibc 2.33 and 2.34, but only the change from 2.34 was reflected so far. Glibc 2.33 finally switched to versioned symbols for stat functions, meaning that libc_nonshared.a no longer contains them since 2.33. Relevant files were therefore reverted to 2.32 versions and renamed accordingly. This commit also removes errno.c, which was probably added to libc_nonshared.a based on a wrong assumption that glibc/include/errno.h requires glibc/csu/errno.c. In reality errno.h should refer to __libc_errno (not to be confused with the public __errno_location), which should be imported from libc.so. The inclusion of errno.c resulted in wrong compile options as well; this commit fixes them as well. Fixes ziglang#16152
Effectively reverts 3dcd361.
3855b71
to
982bbc2
Compare
I reproduced the test failures locally on this PR. Its failing to compile the new files when they're used (so the zig build itself works, but building a gnu-libc test case fails):
The line its complaining about is:
From what I can tell (manually running the compile command with Yeah, "weak_hidden_alias" (and a bunch of other macros) were removed from glibc's include/libc-symbols.h in 2022: in https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=include/libc-symbols.h;h=f4437ff6ad770ce79b4beefe08cb9adfa0b6e6da;hp=4fde8394718454d9e11a6485155fa4e7c83922fb;hb=62595e89447c09fe4e34cd9fc1d4cf1b7f3ecb33;hpb=8ee2c043cfb35c48b45c7c5aed4022a8a7352bdc I'll poke around and see if changing "weak_hidden_alias()" to something else, or putting the header definitions back in makes sense. I may be off base on this, though. |
Oops, yeah, I wasn't paying attention (my local LLVM compilation is currently out of date, so I only checked histories of conflicting files). I agree that simply reviving
|
Pasting the old definitions of The patch is available at c76fbfa But its just this diff for libc-symbols.h:
I wasn't sure if I should push something, or wait for one of you to cherry-pick into this tree. Just redoing the patch is fine with me too. |
I also noticed a test is disabled because of the bug this PR is fixing, so that is probably worth enabling in this stack. There is at least: jacobly0@01f9cdd (a quick search found no others). |
Work is continuing at #17702 |
In lieu of #16152, I tried to compile every glibc version from 2.32 to 2.38 (the most recent) to see any differences. It turns out that recent changes to
glibc.zig
didn't take account of Makefile changes, and #16152 was only a symptom of this broader issue. This PR updatesglibc.zig
to take account for the following:stat
functions fromlibc_nonshared.a
tolibc.so
, using the usual ELF symbol versioning. In fact, AFAIK the ELF symbol versioning was a response to the experience fromlibc_nonshared.a
(which can technically violate ODR), and these were the last functions to adapt it. (bminor/glibc@8ed005d, bminor/glibc@589260c, bminor/glibc@4d97cc8, bminor/glibc@99468ed)libc_nonshared.a
. 3dcd361 can be also safely reverted (they were a simple portable redirection before 2.33).glibc/include/errno.h
among others to access__libc_errno
. But it is defined fromlibc.so
, soglibc/csu/errno.c
should not be added.-DSHARED
option only applies to*.os
files, i.e. objects compiled intolibc.so
.*.oS
(note the capitalS
) files forlibc_nonshared.a
never needed them and I've verified that glibc 2.32 only passes-DLIBC_NONSHARED=1
for all*.oS
files.libc_nonshared.a
. I've checked remaining 4 objects; they all agree with the shipped version except for header inlining.Now, given this PR deals with multiple glibc versions, I couldn't fully test it. I did however test:
zig cc -target x86_64-linux-gnu.2.31
still compileslibc_nonshared.a
with all stat functions but noerrno.o
and correctly produces a working shared object for the original example.zig cc -target x86_64-linux-gnu.2.34
compileslibc_nonshared.a
with only 4 object files remaining since 2.34. I don't have any Linux environment with glibc 2.32 or later so I couldn't directly test it, but at least it correctly compiles with astat@plt
trampoline (as opposed to__xstat@plt
) to thestat@GLIBC_2.33
symbol.ci/x86_64-linux-release.sh
successfully passes. This covers any unintentional changes for non-glibc targets. I intended to produce a full distribution suitable for zig-pypi, so I took some more time.Any additional verification for other glibc versions and
test-std
against them would be appreciated.